import Calculate from './Calculate.js'
import { AmapWEbApiKey } from './setting.js'
function mapRequest(url) {
  let promise = new Promise(function(resolve,reject) {
    uni.request({
      url,
      success: res => {
        if (res.data.status === '1') {
			console.log('11');
			console.log(res.data);
          resolve(res.data)
        } else {
          
          reject(new Error('高德地图api错误'))
        }
      },
      fail: () => {
        reject(new Error('网络错误'))
      },
    })
  })
}
export const getRegeo = (location) => {
	uni.request({
	    url:'https://restapi.amap.com/v3/geocode/regeo',
		method: "GET",
		data: {
			location,
			extensions: 'all',
			key: AmapWEbApiKey,
		},
	    success: res => {
	      if (res.data.status === '1') {
				console.log('11');
				console.log(res.data);
				return res.data
	      } else {
	        console.log(res);
	      }
	    },
	    fail: () => {
			console.log("网络错误");
	    },
	})
}
export async function getInputtips(keywords){
  const res = await mapRequest('https://restapi.amap.com/v3/assistant/inputtips' + Calculate.objToParams({
    keywords,
    key: '0a63ee5182246385f7460740f192c60f',

  })).then(res => res.json())
  return res
}

